<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <input type="text" v-model="inputTxt">
    {{ inputTxt }}
    {{ reverseMsg }}
    <hr>
    <input type="text" v-model="obj.a">
    <input type="text" v-model="obj.b">
    {{ obj.a }}
  </div>
  <script src="./vue.js"></script>
  <script>
    const vm = new Vue({
      el: '#app',
      data: {
        inputTxt:'',
        reverseMsg: '',
        obj: {
          a: 'a',
          b: 'b'
        }
      },
      watch: {
        inputTxt(newVal, oldVal){
          console.log(newVal, 11);
          console.log(oldVal, 22);
          this.reverseMsg = newVal.split('').reverse().join('')
        },
        "obj.a"(newVal,oldVal){
          // console.log(newVal);
        },
        // 监听对象
        obj: {
          handler(newVal){
            console.log(newVal);
          },
          // 深度监听
          deep: true
        }
      }
    })
  </script>
</body>
</html>